package com.bankcomm.common;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Stack;
import java.util.Timer;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.DialogInterface.OnClickListener;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.bankcomm.R;
import com.bankcomm.ui.BOCMainHome;
import com.bankcomm.ui.BOCPushMessage;
import com.bankcomm.ui.BaseViewCopy;
import com.bankcomm.ui.EMPView;
import com.bankcomm.ui.SplashScreenActivity;
import com.bankcomm.common.UserManager;
import com.rytong.tools.crypto.AESCipher;
import com.rytong.tools.datastorage.PackageManagerAndroid;
import com.rytong.tools.httpconnect.HttpManager;
import com.rytong.tools.httpconnect.WaitDialog;
import com.rytong.tools.httpconnect.HttpManager.NoGatewayException;
import com.rytong.tools.ui.Component;
import com.rytong.tools.ui.CssStyle;
import com.rytong.tools.ui.ImageRepository;
import com.rytong.tools.utils.Utils;
import com.zc.card.AudioCardManager;

public class LPMid {

    private static LPMid mid_;
    Activity activity_;
    public HttpManager hm_;
    public PackageManagerAndroid pm_;
    public WaitDialog waitDialog_;
    WaitDialog dlg_;
    // PoiRepository lastValidPoiRepo_; // It's the last valid poi repository
    // which was shown on the screen before waiting view.
    // PoiListSelection lastValidPoiListSelection_; // It's the last valid poi
    // list selection which was shown on the screen before waiting view.

	/** 正在加载的图片 */
	private static Drawable loadingImg_ = null;

    static final int PIN_NUMBER_LENGTH = 16;
    static final int MIN_PIN_NUMBER_LENGTH = 4;

    /**
     * stack of windows to drive back actions. before we go to a screen, we do push the current screen in this stack. if
     * we will back from a screen, we do pop a screen from this stack. if an action fails in the wait dialog, we do pop
     * a screen also.
     */
    Stack stackWindows_;
    /* view indexes. */
    static final int CANVAS = 100; // just back to canvas when set this.
    static final int LAUNCHER_SCREEN = 0;
    static final int CHANNEL_LIST = 1;
    static final int POI_LIST = 2;
    static final int MAP_VIEW = 3;
    static final int SET_LOCATION = 5;
    static final int QUERY_VIEW = 6;
    static final int POI_DETAIL = 7;
    static final int OPTION_VIEW = 9;
    static final int LOGIN_VIEW = 11;
    static final int HELP_VIEW = 12;
    static final int SHOWLOG_VIEW = 14;
    static final int BOC_MAIN_VIEW = 16;
    static final int BOC_DETAIL_VIEW = 17;

    private Timer timer_;

    /** SMS port used by us for PushRegistry */
    // final String smsPort_;
    /** Phone Model for MIDlet version update */
    String phoneModel_;

    /** MIDlet version for version update */
    public String midletVersion_;

    /**
     * If we are launched by PushRegistry, this tells us the pending connections.
     */

    /** It's ture, if it's the first log in */
    boolean isFirstLogin_;

    static final String FIND_STR = "Find";

    private LPAlert lpAlert_;

    /** True if we should check and respond to new software versions */
    boolean updateMode_;

    /**
     * Remember if the last login request has found a new software version. Will be modified from login procedure and
     * from UserManager's background login process.
     */
    int foundUpdate_;

    boolean isInAccountList_; // indicate if it is NOW in an account list or
    // not.
    boolean isInBranchCustom_; // indicate if it is in branch custom or not.
    String currentFilePath_ = "";

    // 注册命令
    private final int loginShowLogCmd_ = 0;
    /** Alert for version update. */
    private final int updateAlertOk_ = 1;
    private final int updateAlertCancel_ = 2;

    /**
     * 保存缓存的DIV,有些时候部分页面中的DIV过长， 反复读取解析太费时间，这里将需要缓存的DIV保存起来，跳过解析
     */
    protected HashMap<String, ArrayList<Component>> cacheDivs;

    /** 缓存DIV的Styles */
    protected HashMap<String, CssStyle> cacheDivStyles_;

    boolean isInterrupteLoad_;
	public UserManager um_;
	
	//密码键盘
//调试
//	public String[] num = {"4","3","2","1","0","5","6","7","9","8"};//保存随机键盘数
//
//	public String[] letter = {"a","e","d","4","3","2","m","z","p","v"};//保存要传的内容

	public String[] num  ;//保存随机键盘数

	public String[] letter ;//保存要传的内容

	public boolean isRandomPass=false;//设置是否存栈，有随机键盘的页面不存栈
	
	public String serverRandom="";

	public String keyValues="";
	//密码键盘在一个form有多个密码键盘输入框时，保存密码键盘的对应序列
	public static String digitStr = null ;
	public boolean isNeedGetKey = false ;
    /**
     * Progress indictor image.
     */
    public static Bitmap progress_;
    
    /** 偏移url集合 */
	public List<String> urlList = new ArrayList<String>();
	
	/** 周边搜索分类 */
	public HashMap<Integer, String> bigMap = null; // 大类数据
	public HashMap<Integer, HashMap<Integer, String>> smallMap = null; // 小类数据
	public String bigClass[] = null;
	public String smallClass[][] = null;
	
	/** 商圈城市分类 */
	public HashMap<Integer, String> bigCityMap = null; // 大类数据
	public HashMap<Integer, HashMap<Integer, String>> smallCityMap = null; // 小类数据
	public String bigCityClass[] = null;
	public String smallCityClass[][] = null;

	/** 当前网点体 */
	public String currentBranchBody = null;
	
	/** 音频卡对象 */
	public AudioCardManager audioCardManager;
	/**存储音频卡信息**/
	public HashMap<String,String> audioCardInfo;
	
	public double currentLon;
	public double currentLat;
	
	public double getLon;
	public double getlat;
	
	//特惠商戶
	public HashMap<Integer, String> bigMostPopMap;
	public HashMap<Integer, HashMap<Integer, String>> smallMostPopMap;
	public String[] bigMostPopClass;
	public String[][] smallMostPopClass;
	public int defaultRadiobut=0;
	public Bitmap QRBitMap ;

	/**
	 * 数据库,大学生版本的学校
	 */
	public SQLiteDatabase db;
	public static boolean isSB = false;

	//判断是否是超时 add by cheng.l
	public boolean isTimeOut = false;
	//记录当前选择的频道 add by cheng.l
	public int currentTab = 0;
	public boolean isShow=false;
	public boolean notShowDialog=false;
	
	/*标记是推送页面进入EMPView的*/
	public static boolean isPushActivity = false;
	public static int indexTab = 0;
    /**
     * Creates a new instance of LPMidlet
     */
    public LPMid(Activity activity) {
        mid_ = this;
        try {
            activity_ = activity;

            PackageManager pm = activity.getPackageManager();
            PackageInfo pi = pm.getPackageInfo(activity.getPackageName(), PackageManager.GET_ACTIVITIES);

            phoneModel_ = ConfigManager.phoneModel_;
            midletVersion_ = pi.versionName + "";

            stackWindows_ = new Stack();
            updateMode_ = true;
            foundUpdate_ = 0;
            isFirstLogin_ = false;

            ConfigManager.makeUserAgent(phoneModel_, midletVersion_);

            if (lpAlert_ == null)
                lpAlert_ = new LPAlert();
        } catch (NameNotFoundException e) {
            // TODO Auto-generated catch block
            Utils.printException(e);
        }
    }

    /**
     * @return
     */
    public static LPMid getInstance() {
        return mid_;
    }

    /**
     * Called from SplashScreen. Any exception thrown from here will be caught by SplashScreen.
     */
    public void initLightPoleApp(Activity lps) throws Exception {
        // Don't initialize this twice.
        if (hm_ == null)
            hm_ = new HttpManager(lps);
        if (pm_ == null)
            pm_ = new PackageManagerAndroid(lps);
        pm_.permDB_.init();
        
        if (um_ == null) {
			um_ = new UserManager(this, hm_, pm_, lps);
		}

        if (waitDialog_ == null){
            waitDialog_ = new WaitDialog();
        }

        pm_.initStorage();
//        修改从类中读取
//        ConfigManager.SERVER_URI = Utils.getConfigStringFormAsset(lps, "SERVER_URI");
//        ConfigManager.SERVER_URI_NO_PORT = Utils.getConfigStringFormAsset(lps, "SERVER_URI_NO_PORT");
        
       
    }

    private void getFile(final String string, final EMPView bv) {
        // TODO Auto-generated method stub
        try {
            if (string.equals(currentFilePath_)) {
                getDataSource(string, bv);
            }
            currentFilePath_ = string;
            Runnable r = new Runnable() {

                public void run() {
                    // TODO Auto-generated method stub
                    try {
                        getDataSource(string, bv);
                    } catch (Exception e) {
                        Utils.LogD(Utils.LOGNAME, "LPMid-getFile-e:" + e.toString());
                    }
                }

            };
            new Thread(r).start();
        } catch (Exception e) {
            Utils.printException(e);
        }
    }

    private void getDataSource(String strPath, EMPView bv) throws IOException {
        // TODO Auto-generated method stub
        // 取得URL
        URL urlTemp = new URL(strPath);
        // 创建连接
        URLConnection conn = urlTemp.openConnection();
        conn.connect();
        // 下载文件
        InputStream is = conn.getInputStream();
        if (null == is) {
            throw new RuntimeException("stream is null");
        }
        // 创建临时文件
        File fileTemp = File.createTempFile("update", ".XX");
        // 取得临时文件路径
        String currentTempFilePath = fileTemp.getAbsolutePath();
        // 将文件写入暂存盘
        FileOutputStream fos = new FileOutputStream(fileTemp);
        byte buf[] = new byte[128];
        do {
            int numread = is.read(buf);
            if (numread <= 0) {
                break;
            }
            fos.write(buf, 0, numread);
        } while (true);
        // 打开文件进行安装
        openFile(fileTemp, bv);
        try {
            is.close();
        } catch (Exception e) {
            Utils.LogD(Utils.LOGNAME, "LPMid-getDataSource-e:" + e.toString());
        }
    }

    private void openFile(File fileTemp, EMPView bv) {
        // TODO Auto-generated method stub
        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(android.content.Intent.ACTION_VIEW);
        String type = Utils.getMIMEType(fileTemp);
        intent.setDataAndType(Uri.fromFile(fileTemp), type);
        bv.startActivity(intent);
    }

    public void alert(Activity activity, String str, boolean isSendLog) {
        activity_ = activity;
        if (lpAlert_ == null) {
            lpAlert_ = new LPAlert();
        }
        lpAlert_.infoAlert(activity_, this, str, isSendLog);
    }

    public void alert(Activity activity, String str, int nextScreen, boolean isSendLog) {
        activity_ = activity;
        if (lpAlert_ == null) {
            lpAlert_ = new LPAlert();
        }
        lpAlert_.infoAlert(activity, this, str, isSendLog);
    }

    void removeDisplayable() {
        if (stackWindows_ != null)
            stackWindows_.removeAllElements();
    }

    /**
     * Removes the object at the top of this stack and returns that object as the value of this function.
     */
    String[] popDisplayable() {
        String[] view = null;
        if (stackWindows_ != null && !stackWindows_.empty()) {
            String[][] temp = new String[stackWindows_.size()][];
            stackWindows_.copyInto(temp);
            for (int i = 0; i < temp.length; i++) {
                Utils.printOutToConsole("############################### popDisplayable() see stack view  " + i + " = "
                        + temp[i][0] + ", and id = " + temp[i][1] + ", title = " + temp[i][2]);
            }
            try {
                view = (String[]) stackWindows_.pop();
                Utils.printOutToConsole("############################### popDisplayable() out view  = " + view[0]
                        + ", and id = " + view[1] + ", title = " + view[2]);
            } catch (Exception ex) {
            }
        }
        return view;
    }

    /**
     * if a view diferrent the view of the top of this stack, we will push it.
     */
    final void pushDisplayable(int view, String id, String title) {
        if (stackWindows_ != null) {
            String[] top = peekDisplayable();
            int topView = -1;
            try {
                if (top != null)
                    topView = Integer.parseInt(top[0]);
                Utils.printOutToConsole("############################### pushDisplayable() current topView = "
                        + topView + ", id = " + top[1] + ", title = " + top[2]);
            } catch (Exception ex) {
            }
            if (top != null) {
                if (topView != view) {
                    stackWindows_.push(new String[] { "" + view, id, title });
                    Utils.printOutToConsole("############################### pushDisplayable() into view = " + view
                            + ", id = " + id + ", title = " + title);
                } else {
                    if (id != null) {
                        if (!id.equals(top[1])) {
                            stackWindows_.push(new String[] { "" + view, id, title });
                            Utils.printOutToConsole("############################### pushDisplayable() into view = "
                                    + view + ", id = " + id + ", title = " + title);
                        }
                    } else if (top[1] != null) {
                        stackWindows_.push(new String[] { "" + view, id, title });
                        Utils.printOutToConsole("############################### pushDisplayable() into view = " + view
                                + ", id = " + id + ", title = " + title);
                    }
                }
            } else {
                stackWindows_.push(new String[] { "" + view, id, title });
                Utils.printOutToConsole("############################### pushDisplayable() into view = " + view
                        + ", id = " + id + ", title = " + title);
            }
        }
    }

    /**
     * Looks at the object at the top of this stack without removing it from the stack.
     */
    String[] peekDisplayable() {
        String[] view = null;
        if (stackWindows_ != null && !stackWindows_.empty()) {
            String[][] temp = new String[stackWindows_.size()][];
            stackWindows_.copyInto(temp);
            for (int i = 0; i < temp.length; i++) {
                Utils.printOutToConsole("############################### peekDisplayable() see stack view  " + i
                        + " = " + temp[i][0] + ", and id = " + temp[i][1] + ", title = " + temp[i][2]);
            }
            try {
                view = (String[]) stackWindows_.peek();
            } catch (Exception ex) {
            }
        }
        return view;
    }

    /**
     * Download and cache thumbnail image in this POI.
     * 
     * @param imgUrl
     * @param index
     * @param width
     * @param height
     * @param images
     * @throws Exception
     */
    public void downloadImage(String imgUrl, int index, int width, int height, ArrayList<Bitmap> images)
            throws Exception {
        Bitmap image = null;
        if (imgUrl != null) {
            StringBuffer url = new StringBuffer();
            url.append(ConfigManager.SERVER_URI);
            url.append(ConfigManager.GET_PIC_URI);
            url.append("url=");
            url.append(Utils.escapeURIComponent(imgUrl));
            url.append("&w=");
            url.append(width);
            url.append("&h=");
            url.append(height);

            String strUrl = url.toString();

            Utils.printOutToConsole("download image : url=" + url + " index=" + index);
            try {
                byte[] imageBytes = null;
                int sqlRow = -2;
                if (strUrl.startsWith("local")) {
                    if (imageBytes == null) {
                        ByteArrayOutputStream imageBuffer = new ByteArrayOutputStream(1024);
                        hm_.read(url.toString(), imageBuffer, null);
                        imageBytes = imageBuffer.toByteArray();
                        imageBuffer.close();
                    }
                } else {
                    ByteArrayOutputStream imageBuffer = new ByteArrayOutputStream(1024);
                    hm_.read(url.toString(), imageBuffer, null);
                    imageBytes = imageBuffer.toByteArray();
                    imageBuffer.close();
                }

                image = Utils.getBitmap(imageBytes);
                images.add(index, image);
            } catch (Exception e) {
                // images.insertElementAt(Utils.createImageLoadFail(),
                Utils.printException(e);
                throw e;
            } catch (OutOfMemoryError oe) {
                // images.insertElementAt(Utils.createImageLoadFail(),
                Utils.printOutToConsole(oe.toString());
                throw oe;
            }
        }
    }

    String[] peekDisplayable(int depth) {
        String[] view = null;
        if (stackWindows_ != null && !stackWindows_.empty()) {
            try {
                view = (String[]) stackWindows_.elementAt(stackWindows_.size() - 1 - depth);
            } catch (Exception ex) {
            }
        }
        return view;
    }

    /**
     * @param link
     * @param bv
     */
    void dealWithLink(String link, EMPView bv) {
        try {
            dialWeb(link, bv);
        } catch (Exception ex) {
        }
    }

    // 打开网页操作
    void dialWeb(final String url, EMPView bv) throws Exception {
        bv.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
    }

    Timer timer() {
        if (timer_ == null)
            timer_ = new Timer();
        return timer_;
    }

    static void exitSystem(final EMPView activity) {
        final Activity activityTemp = activity;
        new AlertDialog.Builder(activityTemp).setTitle("提示").setMessage(R.string.exit_prompt).setCancelable(true)
                .setPositiveButton("确定", new OnClickListener() {

                    public void onClick(DialogInterface arg0, int arg1) {
                        // TODO Auto-generated method stub
                        WaitDialog.cancelProgressBar(activity);
                        activityTemp.finish();
                    }
                }).setNegativeButton("取消", new OnClickListener() {

                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }
                }).show();
    }

    static Bitmap createImgWaitLoad(LPMid mid, String alt) {
        Paint paint = new Paint();
        Bitmap imgWaitLoad;

        if (alt != null) {
            paint.setTypeface(Typeface.DEFAULT);
            paint.setTextSize(ConfigManager.SIZE_IMGWAITLOAD);
            int w = (int) paint.measureText(alt) + 2;
            int h = 50;
            imgWaitLoad = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(imgWaitLoad);
            paint.setColor(0x88888888);
            canvas.drawRect(0, 0, w - 1, h - 1, paint);
            paint.setColor(0xffffffff);
            canvas.drawText(alt, 0, h / 2, paint);
            mid.waitDialog_.drawProcessing(canvas, w / 2 - progress_.getWidth() / 2,
                    (h + ConfigManager.SIZE_IMGWAITLOAD) / 2);
        } else {
            int wh = (int) (4 * paint.getTextSize());
            imgWaitLoad = Bitmap.createBitmap(wh, wh, Bitmap.Config.RGB_565);
            Canvas canvas = new Canvas(imgWaitLoad);
            canvas.drawRect(0, 0, wh - 1, wh - 1, paint);
            mid.waitDialog_.drawProcessing(canvas, wh / 2 - progress_.getWidth() / 2, wh / 2);
        }

        return imgWaitLoad;
    }

    public static void init(Activity app) {
        try {
            progress_ = ImageRepository.decodeBitmap(app.getResources(), R.drawable.progress);
        } catch (Exception ex) {
            Utils.printException(ex);
        }
    }
    
    /**
	 * 隐藏系统输入键盘
	 * @param activity  活动
	 */
	public static void hideInputMethod(Activity activity) {
		InputMethodManager inputMethod = (InputMethodManager) activity.getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE);
		if (inputMethod.isActive() && activity.getCurrentFocus() != null) {
			inputMethod.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
		}
	}

	public static Drawable getLoadingImage(Context context) {
		if (null == loadingImg_) {
			loadingImg_ = context.getResources().getDrawable(R.drawable.img_waiting);
		}

		return loadingImg_;
	}
	
	public void initCityData(String cityType) {
		bigCityMap = new HashMap<Integer, String>(); // 大类数据
		smallCityMap = new HashMap<Integer, HashMap<Integer, String>>(); // 小类数据
		try {
			JSONArray jsonArray = new JSONArray(cityType);
			if (jsonArray.length() > 0) {
				bigCityClass = new String[jsonArray.length()];
				smallCityClass = new String[jsonArray.length()][];
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject jsonObject = new JSONObject(jsonArray.getString(i));
					String key = jsonObject.keys().next().toString();
					bigCityClass[i] = key;
					Object value = jsonObject.get(key);
					if (value instanceof JSONArray) {
						String[] valueCity = null;
						JSONArray valueJson = new JSONArray(value.toString());
						if (valueJson.length() > 0) {
							valueCity = new String[valueJson.length()];
							HashMap<Integer, String> cityMap = new HashMap<Integer, String>();
							for (int j = 0; j < valueJson.length(); j++) {
								JSONObject valJsonObject = new JSONObject(valueJson.getString(j));
								String valKey = valJsonObject.keys().next().toString();
								valueCity[j] = valKey;

								// 小类
								cityMap.put(j, valJsonObject.get(valKey).toString());
							}
							smallCityMap.put(i, cityMap);
							smallCityClass[i] = valueCity;
						}
					} else {
						// 大类
						bigCityMap.put(i, value.toString());
						smallCityClass[i] = new String[] {};
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
	}

	public void initMostPopData(String shopType) {
		bigMostPopMap = new HashMap<Integer, String>(); // 大类数据
		smallMostPopMap = new HashMap<Integer, HashMap<Integer, String>>(); // 小类数据
		try {
			JSONArray jsonArray = new JSONArray(shopType);
			if (jsonArray.length() > 0) {
				bigMostPopClass = new String[jsonArray.length()];
				smallMostPopClass = new String[jsonArray.length()][];
				for (int i = 0; i < jsonArray.length(); i++) {
					JSONObject jsonObject = new JSONObject(jsonArray.getString(i));
					String key = jsonObject.keys().next().toString();
					bigMostPopClass[i] = key;
					Object value = jsonObject.get(key);
					if (value instanceof JSONArray) {
						String[] valueCity = null;
						JSONArray valueJson = new JSONArray(value.toString());
						if (valueJson.length() > 0) {
							valueCity = new String[valueJson.length()];
							HashMap<Integer, String> cityMap = new HashMap<Integer, String>();
							for (int j = 0; j < valueJson.length(); j++) {
								JSONObject valJsonObject = new JSONObject(valueJson.getString(j));
								String valKey = valJsonObject.keys().next().toString();
								valueCity[j] = valKey;

								// 小类
								cityMap.put(j, valJsonObject.get(valKey).toString());
							}
							smallMostPopMap.put(i, cityMap);
							smallMostPopClass[i] = valueCity;
						}
					} else {
						// 大类
						bigMostPopMap.put(i, value.toString());
						smallMostPopClass[i] = new String[] {};
					}
				}
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}
		
	}
	
	public Dialog creatDialog(Dialog dialog,String msg,Activity act){
		RelativeLayout line = (RelativeLayout) LayoutInflater.from(act).inflate(R.layout.layout_wait_progress, null);
		TextView message = (TextView)line.findViewById(R.id.tv);
		message.setText(msg);
		dialog = new Dialog(act, R.style.dialog);
		dialog.setContentView(line);
		Window mWindow = dialog.getWindow();
		mWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
		mWindow.setLayout(ViewGroup.LayoutParams.FILL_PARENT,ViewGroup.LayoutParams.FILL_PARENT);
		WindowManager.LayoutParams lp = mWindow.getAttributes();
		lp.dimAmount = 0f;
		
		return dialog;
	}

	/**
	 * 跳转到EMPView
	 **/
	public void JumpToEMPView(String url ,String RequestBody,BaseViewCopy bv){
		String reply = null ;
		String body = RequestBody ;
		
		try {
			if(body!= null && body != ""){
				body = AESCipher.encrypt(body, AESCipher.clientKey_, AESCipher.clientIv_);
			}
			reply = (String) hm_.sendPostRequest(url, body, null, null, null);
			reply = AESCipher.decrypt(reply, AESCipher.serverKey_, AESCipher.serverIv_);
		} catch (NoGatewayException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		}
		Utils.printOutToConsole("++++++++JumpToEMPView+++++++----------"+reply);
		Intent intent = new Intent(bv,EMPView.class);
		intent.putExtra("reply", String.valueOf(reply));
		bv.startActivity(intent);
	}
	
	/**
	 * 保存到SharePreference
	 * @param key
	 * @param value
	 */
	public void saveToSP(String key,String value){
		if(null != key){
			PackageManagerAndroid.ANDROIDDB.save(key, value);
		} 
	}
	
	/**
	 * 读取从SharePreference
	 * @param key
	 * @return
	 */
	public String read(String key){
		String temp = PackageManagerAndroid.ANDROIDDB.get(key);
		
		if(temp == null || "".equalsIgnoreCase(temp)){
			temp = null;
		}
		return temp;
	}

	public void jumptoBOCHome(Activity activity){
		Intent intent = new Intent();
		if (LPMid.getInstance().um_.data.stepIntoPushMessage()) {
			intent.setClass(activity,
					BOCPushMessage.class);
		} else {
			intent.setClass(activity,
					BOCMainHome.class);
		}
		activity.startActivity(intent);
		activity.finish() ;
	}
}
